<!--#include file="./header.inc"-->
<%

select case aq
	'批量搜索替换
	case "save"		:	call save
	case else 		: 	call index
end select

call db.close()

function index()
	%><!--#include file="./view/replace.index.html"--><%
end function

function save()
	dim reType, reContent, resultContent, rContent, shortName, iTable, iTitle, iContent
	reType = app.int(request.form("reType"))
	reContent = request.form("reContent")
	resultContent = request.form("resultContent")
	if reContent = "" then admin.message "要替换的内容不能为空！"
	if reType < 1 or reType > 5 then admin.message "替换类型不存在！"
	str = ""
    iTitle = "title"
	iContent = "content"
    select case reType
        case 1
            iTable = "product"
            shortName = "产品"
        case 2
            iTable = "book"
            shortName = "留言"
        case 3
            iTable = "news"
            shortName = "文章"
        case 4
            iTable = "our"
            shortName = "企业简介"
        case 5
            iTable = "view"
            iTitle = "viewName"
            iContent = "viewContent"
            shortName = "模板"
        case else
            iTable = ""
    end select
    if iTable <> "" then
        sql = "select id," & iTitle & "," & iContent & " from cj_" & iTable
        'sql = sql & " where " & iContent & " like '%" & reContent & "%'"
        if batchId <> 0 then
            sql = sql & " where id in(" & batchId & ")"
        end if
        set rs = db.exec(sql, 3)
        if not(rs.eof) then
            i = 0
            do until rs.eof
                rContent = rs(2)
                rContent = replace("" & rContent & "", "" & reContent & "", "" & resultContent & "")
                rs(2) = rContent
                rs.UpDate
                i = i + 1
                str = str & "<p>" & shortName & "id：" & rs(0) & "，名称：" & rs(1) & "</p>"
            rs.movenext : loop
            str = str & "<p>共替换了 <strong>" & i & "</strong> 项" & shortName & "</p>"
        else
            str = "<p>" & shortName & " 没有找到“<strong>" & reContent & "</strong>”的内容</p>"
        end if
        rs.close : set rs = nothing
    end if
	admin.back str, "返回", "?q=index"
end function

%>